package com.micai.springboot.mq;

import com.micai.springboot.base.BaseConfig;
import com.micai.springboot.entity.User;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 描述：消息消费者
 * @RabbitListener注解定义该类对hello队列的监听，
 * 并用@RabbitHandler注解来指定对消息的处理方法。
 * 所以，该消费者实现了对hello队列的消费，消费操作为输出消息的字符串内容
 * Author: 赵新国
 * Date: 2017/11/3 15:42
 */
@Component
public class Receiver extends BaseConfig {

    // ---------------------------------------------------- Direct 形式 -------------------------------------------- //
    //监听器监听指定的Queue
    /*@RabbitListener(queues = QUEUE_KEY)
    public void process(String str) {
        System.out.println("接收MQ消息 : " + str);
    }*/

    // //监听器监听指定的Queue
    /*@RabbitListener(queues = QUEUE_KEY)
    public void process(User user) { //用User作为参数
        System.out.println("接收MQ消息 : " + user);
    }*/

    // ---------------------------------------------------- Topic 形式 -------------------------------------------- //
    /*@RabbitListener(queues="topic.message")    //监听器监听指定的Queue
    public void process1(String str) {
        System.out.println("message:"+str);
    }

    @RabbitListener(queues="topic.messages")    //监听器监听指定的Queue
    public void process2(String str) {
        System.out.println("messages:"+str);
    }*/


    // -------------------------------------------- Fanout Exchange形式 ------------------------------------------- //
    @RabbitListener(queues="fanout.A")
    public void processA(String str1) {
        System.out.println("ReceiveA:"+str1);
    }

    @RabbitListener(queues="fanout.B")
    public void processB(String str) {
        System.out.println("ReceiveB:"+str);
    }

    @RabbitListener(queues="fanout.C")
    public void processC(String str) {
        System.out.println("ReceiveC:"+str);
    }

}
